package com.fyy.socket.tcp;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * @Author fyy
 * @Description
 * @Date 2020/12/10 11:03
 */
public class LoginClient {

    public static void main(String[] args) throws IOException {
        //建立socket连接
        Socket socket = new Socket("127.0.0.1",8080);
        DataInputStream dis = new DataInputStream(socket.getInputStream());
//        DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
        ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
        //获取键盘输入，封装成User对象
        Scanner input = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String userId = input.next();
        System.out.println("请输入密码：");
        String password = input.next();
        User user = new User(userId,password);
        //发送数据
        oos.writeObject(user);
        //获取返回数据
        String str = dis.readUTF();
        System.out.println("服务器返回数据:" + str);
        //关闭连接
        oos.close();
        dis.close();
        //socket.close(); //不需要手动关闭
    }

}
